<template>
  <div class="boxBg">
    <div class="search">
      <div class="searchType">
        <a href="javasCript:;" v-for="item in searchChoose" :key="item.id"
          :class="item.choose ? 'chosen' : ''"
          @click="changeSearchType(item.id)">{{ item.title }}</a>
      </div>
      <div class="sjx" :style="{ 'margin-left': sjxLeft + 'px' }"></div>
      <div class="searchInput">
        <input type="text" v-model="searchInput" placeholder="请输入区域、商圈或小区名开始找新房" />
        <button @click="search">
          <img src="@/assets/搜索.svg" />
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue'
export default defineComponent({
  setup () {
    const searchInput = ref('')
    const sjxLeft = ref(15)
    const searchChoose = ref([
      {
        id: 1,
        title: '找新房',
        name: 'new',
        choose: true
      },
      {
        id: 2,
        title: '找二手房',
        name: 'old',
        choose: false
      },
      {
        id: 3,
        title: '找租房',
        name: 'rent',
        choose: false
      },
      {
        id: 4,
        title: '找商业写字楼',
        name: 'office',
        choose: false
      },
      {
        id: 5,
        title: '找装修',
        name: 'furnish',
        choose: false
      }
    ])
    const changeSearchType = (id) => {
      searchChoose.value.forEach(item => {
        if (item.id === id) {
          item.choose = true
        } else {
          item.choose = false
        }
      })
      if (id === 1) {
        sjxLeft.value = 15
      } else if (id === 2) {
        sjxLeft.value = 115
      } else if (id === 3) {
        sjxLeft.value = 210
      } else if (id === 4) {
        sjxLeft.value = 320
      } else if (id === 5) {
        sjxLeft.value = 435
      }
    }
    const search = () => {
      console.log('开始查找')
    }
    return {
      searchChoose,
      changeSearchType,
      sjxLeft,
      search,
      searchInput
    }
  }
})
</script>

<style lang='less' scoped>
.boxBg {
  position: relative;
  background-color: skyblue;
  width: 100%;
  height: calc(100vw * 600 / 1920);
  .search {
    display: block;
    position: absolute;
    padding: 16px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 732px;
    height: 143px;
    background: rgba(16, 29, 55, 0.6);
    border-radius: 12px;
  }
  .searchType {
    a {
      font-family: 'HarmonyOS Sans SC';
      font-style: normal;
      font-weight: 700;
      font-size: 18px;
      margin-left: 16px;
      margin-right: 16px;
      color: rgba(255, 255, 255, 0.5);
    }
    a:first-child {
      margin-left: 0px;
    }
    .chosen {
      color: #fff;
    }
  }
  .sjx {
    width: 0;
    height: 0;
    margin-top: 16px;
    border-bottom: 10px solid #fff;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
  }
  .searchInput {
    display: flex;
    width: 100%;
    height: 64px;
    input {
      box-sizing: border-box;
      width: 600px;
      height: 100%;
      border: 0;
    }
    input::placeholder {
      // margin-left: 20px;
      text-indent: 20px;
      font-family: 'HarmonyOS Sans SC';
      font-style: normal;
      font-weight: 400;
      font-size: 18px;
      color: #9399a5;
    }
    button {
      width: 100px;
      height: 100%;
      background-color: #f15044;
      border: 0;
      img {
        width: 27px;
        height: 27px;
      }
    }
  }
}
</style>
